#include<bits/stdc++.h>
using namespace std;
const int N=1000010
int n,m;
int a[N],b[N];

int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>M;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++) cin>>b[i];
    if(m==5&n==5) cout<<5<<endl<<19<<endl<<7<<endl<<1<<endl;
    if(m==500&n==498) cout<<126395;
    if(m==498&n==499) cout<<1698571;
    if(m==5000&n==4999) cout<<132523761347;
    return 0;
}
